<style scoped>
  @import "../../static/css/weui.css";
    /*         图片播放区 */
  [class*="weui-col-"] {
    border: 1px solid #ccc;
    height: 40px;
    line-height: 40px;
    text-align: center;
  }

  .tzshelp {
    background: #fff;
    margin-bottom: 5px;
    border-top: 1px solid #ddd;
    border-bottom: 1px solid #ddd;
  }

  .tzshelpinner {
    width: 100%;
    overflow: hidden;
  }

  .title {
    text-align: left;
    line-height: 40px;
    text-indent: 8px;
    font-size: 14px;
    border-bottom: 1px solid #f3f3f3;
    background: #fff;
  }
  .task {
    height: 20px !important;
    margin-top: 4px;
  }
  .task img {
    width: 20px !important;
    height: 18px !important;
  }
  .carousel-wrap {
    position: relative;
    overflow: hidden;
  }
</style>
<template>
  <div id="app-main" style="background: #efefef;">
    <!-- 图片滑动区 -->
    <div class="carousel-wrap" ref="carouselWrap">
      <div class="img-box">
        <div class="carousel-slider">
          <img class="carousel-img" src="@/assets/banner1_wechat.png">
        </div>
        <div class="carousel-slider">
          <img class="carousel-img" src="@/assets/banner2_wechat.jpg">
        </div>
      </div>
      <ul class="indicator-list" style="bottom: 0;"></ul>
    </div>
    <div v-if="funcs.some(item => ['2','3','4','5','7','9','12'].includes(item))" class="tzshelp">
      <div class="tzshelpinner">
        <h2 class="title">生产加工</h2>
      </div>
      <div class="weui_grids" id="produce">
        <template v-if="funcs.indexOf('3') > -1">
          <a href="javascript:;" @click="$router.push({path: '/plan2/PlanList'})" class="weui_grid js_grid">
            <div class="weui_grid_icon">
              <img src="@/assets/icon-plan.png" alt="">
            </div>
            <p class="weui_grid_label">
              生产计划
            </p>
          </a>
        </template>
        <template v-if="funcs.indexOf('2') > -1">
          <a href="javascript:;" @click="$router.push({path: '/pickmrial2/PickmrialList'})" class="weui_grid js_grid">
            <div class="weui_grid_icon">
              <img src="@/assets/icon-order.png" alt="">
            </div>
            <p class="weui_grid_label">
              领料单
            </p>
          </a>
        </template>
        <template v-if="funcs.indexOf('2') > -1">
          <a href="javascript:;" @click="$router.push({path: '/applystorerm2/ApplyStoreRmList'})" class="weui_grid js_grid">
            <div class="weui_grid_icon">
              <img src="@/assets/icon-order.png" alt="">
            </div>
            <p class="weui_grid_label">
              入库申请单
            </p>
          </a>
        </template>
        <template v-if="funcs.indexOf('2') > -1">
          <a href="javascript:;" @click="$router.push({path: '/applyback2/ApplyBackList'})" class="weui_grid js_grid">
            <div class="weui_grid_icon">
              <img src="@/assets/icon-addplan.png" alt="">
            </div>
            <p class="weui_grid_label">
              退料单
            </p>
          </a>
        </template>
        <template v-if="funcs.indexOf('12') > -1">
          <a href="javascript:;" @click="$router.push({path: '/transferapply2/TransApplyList'})" class="weui_grid js_grid">
            <div class="weui_grid_icon">
              <img src="@/assets/icon-change.png" alt="">
            </div>
            <p class="weui_grid_label">
              库房调拨
            </p>
          </a>
        </template>
        <template v-if="funcs.indexOf('5') > -1">
          <a href="javascript:;" @click="$router.push({path: '/transferapply3/TransApplyList'})" class="weui_grid js_grid">
            <div class="weui_grid_icon">
              <img src="@/assets/icon-change.png" alt="">
            </div>
            <p class="weui_grid_label">
              其他出入库
            </p>
          </a>
        </template>
      </div>
    </div>
    <div v-if="funcs.some(item => ['1','13','14','16','17','21','25'].includes(item))" class="tzshelp">
      <div class="tzshelpinner">
        <h2 class="title">销售服务</h2>
      </div>
      <div class="weui_grids" id="sale">
        <template v-if="funcs.indexOf('1') > -1">
          <a href="javascript:;" @click="$router.push({path: '/sellform2/SellformList?flowid=36'})" class="weui_grid js_grid">
            <div class="weui_grid_icon">
              <img src="@/assets/icon-order.png" alt="">
            </div>
            <p class="weui_grid_label">
              销售订单
            </p>
          </a>
        </template>
        <template v-if="funcs.indexOf('1') > -1">
          <a href="javascript:;" @click="$router.push({path: '/sellform2/SellformList?flowid=34'})" class="weui_grid js_grid">
            <div class="weui_grid_icon">
              <img src="@/assets/icon-order.png" alt="">
            </div>
            <p class="weui_grid_label">
              电商订单
            </p>
          </a>
        </template>
        <template v-if="funcs.indexOf('1') > -1">
          <a href="javascript:;" @click="$router.push({path: '/sellform2/SellformList?flowid=35'})" class="weui_grid js_grid">
            <div class="weui_grid_icon">
              <img src="@/assets/icon-order.png" alt="">
            </div>
            <p class="weui_grid_label">
              样品订单
            </p>
          </a>
        </template>
        <template v-if="funcs.indexOf('13') > -1">
          <a href="javascript:;" @click="$router.push({path: '/customer2/CustomerList'})" class="weui_grid js_grid">
            <div class="weui_grid_icon">
              <img src="@/assets/buynongzi_wechat.png" alt="">
            </div>
            <p class="weui_grid_label">
              客户管理
            </p>
          </a>
        </template>
        <template v-if="funcs.indexOf('14') > -1">
          <a href="javascript:;" @click="$router.push({path: '/customer2/RechargeList'})" class="weui_grid js_grid">
            <div class="weui_grid_icon">
              <img src="@/assets/icon-recharge.png" alt="">
            </div>
            <p class="weui_grid_label">
              客户充值
            </p>
          </a>
        </template>
        <template v-if="funcs.indexOf('16') > -1">
          <a href="javascript:;" @click="$router.push({path: '/farepay2/FarepayList'})" class="weui_grid js_grid">
            <div class="weui_grid_icon">
              <img src="@/assets/icon-settle.png" alt="">
            </div>
            <p class="weui_grid_label">
              运费支付
            </p>
          </a>
        </template>
        <template v-if="funcs.indexOf('25') > -1">
          <a href="javascript:;" @click="$router.push({path: '/purchase2/PurchaseList'})" class="weui_grid js_grid">
            <div class="weui_grid_icon">
              <img src="@/assets/icon-purchase.png" alt="">
            </div>
            <p class="weui_grid_label">
              采购订单
            </p>
          </a>
        </template>
        <template v-if="funcs.indexOf('22') > -1">
          <a href="javascript:;" @click="$router.push({path: '/purchase2/bill/list'})" class="weui_grid js_grid">
            <div class="weui_grid_icon">
              <img src="@/assets/icon-payed.png" alt="">
            </div>
            <p class="weui_grid_label">
              采购付款申请
            </p>
          </a>
        </template>
      </div>
    </div>
    <div v-if="funcs.some(item => ['15','22','26','27'].includes(item))" class="tzshelp hwrap">
      <div class="tzshelpinner">
        <h2 class="title">采收服务</h2>
      </div>

      <div class="weui_grids hwrap">
<!--        <template v-if="funcs.indexOf('26') > -1">-->
<!--          <a href="javascript:;" @click="$router.push({path: '/harvest/Freightorder'})" class="weui_grid js_grid">-->
<!--            <div class="weui_grid_icon">-->
<!--              <img src="@/assets/zhengce_wechat.png" alt="">-->
<!--            </div>-->
<!--            <p class="weui_grid_label">-->
<!--              采收订单-->
<!--            </p>-->
<!--          </a>-->
<!--        </template>-->
        <template v-if="funcs.indexOf('26') > -1">
          <a href="javascript:;" @click="$router.push({path: '/harvest2/forder/list'})" class="weui_grid js_grid">
            <div class="weui_grid_icon">
              <img src="@/assets/zhengce_wechat.png" alt="">
            </div>
            <p class="weui_grid_label">
              采收订单
            </p>
          </a>
        </template>
        <template v-if="funcs.indexOf('22') > -1">
          <a href="javascript:;" @click="$router.push({path: '/harvest/bill/list'})" class="weui_grid js_grid">
            <div class="weui_grid_icon">
              <img src="@/assets/icon-payed.png" alt="">
            </div>
            <p class="weui_grid_label">
              付款申请
            </p>
          </a>
        </template>
        <template v-if="funcs.indexOf('22') > -1">
          <a href="javascript:;" @click="$router.push({path: '/harvest2/bill/list'})" class="weui_grid js_grid">
            <div class="weui_grid_icon">
              <img src="@/assets/icon-payed.png" alt="">
            </div>
            <p class="weui_grid_label">
              新付款申请
            </p>
          </a>
        </template>
        <template v-if="funcs.indexOf('15') > -1">
          <a href="javascript:;" @click="$router.push({path: '/harvest2/contract/list'})" class="weui_grid js_grid">
            <div class="weui_grid_icon">
              <img src="@/assets/icon-contract.png" alt="">
            </div>
            <p class="weui_grid_label">
              合同
            </p>
          </a>
        </template>
        <template v-if="funcs.indexOf('27') > -1">
          <a href="javascript:;" @click="$router.push({path: '/harvest/makeprice/list?openid=${openid}'})" class="weui_grid js_grid">
            <div class="weui_grid_icon">
              <img src="@/assets/icon-mprice.png" alt="">
            </div>
            <p class="weui_grid_label">
              淀粉薯定价
            </p>
          </a>
        </template>
      </div>
    </div>
<!--    20230801注释-->
    <div v-if="userType == 1" class="tzshelp">
      <div class="tzshelpinner">
        <h2 class="title">植保服务</h2>
      </div>
      <div class="weui_grids">
<!--        <a :href="`http://${locationhost}/trace/PlantInfo!index.action?openid=${openid}`" class="weui_grid js_grid">-->
<!--          <div class="weui_grid_icon">-->
<!--            <img src="@/assets/jilu_wechat.png" alt="">-->
<!--          </div>-->
<!--          <p class="weui_grid_label">-->
<!--            植保记录-->
<!--          </p>-->
<!--        </a>-->
<!--        <a :href="`http://${locationhost}/trace/PlantInfo!index.action?openid=${openid}&flag=Y`" class="weui_grid js_grid">-->
<!--          <div class="weui_grid_icon">-->
<!--            <img src="@/assets/zixun_wechat.png" alt="">-->
<!--          </div>-->
<!--          <p class="weui_grid_label">-->
<!--            专家咨询-->
<!--          </p>-->
<!--        </a>-->
        <template v-if="userType == 1 || userType == 4">
<!--          <a :href="`http://${locationhost}/trace/TArealand!list.action?openid=${openid}`" class="weui_grid js_grid">-->
<!--            <div class="weui_grid_icon">-->
<!--              <img src="@/assets/icon-earth.png" alt="">-->
<!--            </div>-->
<!--            <p class="weui_grid_label">-->
<!--              土地信息-->
<!--            </p>-->
<!--          </a>-->
          <a href="javascript:;" @click="$router.push({path: '/plant2/land/LandList'})" class="weui_grid js_grid">
            <div class="weui_grid_icon">
              <img src="@/assets/icon-earth.png" alt="">
            </div>
            <p class="weui_grid_label">
              土地信息
            </p>
          </a>
        </template>
<!--        <template v-if="userType == 1">-->
<!--          <a :href="`http://${locationhost}/trace/PlantManager!list.action?openid=${openid}`" class="weui_grid js_grid">-->
<!--            <div class="weui_grid_icon">-->
<!--              <img src="@/assets/icon-adminer.png" alt="">-->
<!--            </div>-->
<!--            <p class="weui_grid_label">-->
<!--              基地经理-->
<!--            </p>-->
<!--          </a>-->
<!--        </template>-->
<!--        <template v-if="userType == 4">-->
<!--          <a :href="`http://${locationhost}/trace/Workerarealand!index.action?openid=${openid}`" class="weui_grid js_grid">-->
<!--            <div class="weui_grid_icon">-->
<!--              <img src="@/assets/icon-worker.png" alt="">-->
<!--            </div>-->
<!--            <p class="weui_grid_label">-->
<!--              工作人员-->
<!--            </p>-->
<!--          </a>-->
<!--        </template>-->

      </div>
    </div>
    <div v-if="userType == '00'" class="tzshelp hwrap">
      <div class="tzshelpinner">
        <h2 class="title">系统管理</h2>
      </div>

      <div class="weui_grids">
        <a href="javascript:;" @click="$router.push({path: '/common/CommonRefuse'})" class="weui_grid js_grid">
          <div class="weui_grid_icon">
            <img src="@/assets/icon-back.png" alt="">
          </div>
          <p class="weui_grid_label">
            容错处理
          </p>
        </a>
      </div>
    </div>
    <div style="height: 60px;"></div>
    <div class="weui_tabbar" :style="{visibility: isReady}">
      <a href="javascript:;" @click="$router.push({path: '/index'})" class="weui_tabbar_item weui_bar_item_on">
        <div class="weui_tabbar_icon">
          <img src="@/assets/zhu_wechat.png" alt="">
        </div>
        <p class="weui_tabbar_label">首页</p>
      </a>
      <a href="javascript:;" @click="$router.push({path: '/common/TaskList'})" class="weui_tabbar_item" >
        <div class="weui_tabbar_icon task" id="wait" style="position: relative;">
          <img src="@/assets/task-wechat.png" alt="">
        </div>
        <p class="weui_tabbar_label">待办</p>
      </a>
<!--      20230801注释-->
<!--      <a :href="`http://${locationhost}/trace/TraceSource!index.action?fromConsole=false`" class="weui_tabbar_item">-->
<!--        <div class="weui_tabbar_icon">-->
<!--          <img src="@/assets/source_wechat.png" alt="">-->
<!--        </div>-->
<!--        <p class="weui_tabbar_label">植保</p>-->
<!--      </a>-->
      <a href="javascript:;" @click="$router.push({path: '/mine'})" class="weui_tabbar_item">
        <div class="weui_tabbar_icon">
          <img src="@/assets/wd_wechat.png" alt="">
        </div>
        <p class="weui_tabbar_label">我</p>
      </a>
    </div>
  </div>
</template>
<script type="text/babel">
  import Carousel from 'qt-carousel';
  export default {
    name: 'index',
    data: () => ({
      funcs: [],
      carousel: null,
      userType: localStorage.getItem('userType'),
      isReady: false,
      locationhost: location.host,
      openid: localStorage.getItem('openid')
    }),
    components: {
    },
    beforeRouteEnter(to, from, next) {
      next(vm => {
        console.log('from.fullPath:', from.fullPath)
        if (from.fullPath.indexOf('entry') > -1) {
          vm.getUser();
        }
      })
    },
    created() {
      this.getFuncs();
    },
    mounted() {
      this.isReady = true;
      console.log('locationhost:', this.locationhost)
      if(this.locationhost.indexOf('test') > -1){
        this.toastError('金名测试环境!!!');
      }
      this.carousel = new Carousel();
      this.carousel.init(this.$refs.carouselWrap);
    },
    methods: {
      getUser: function () {
        this.axios({
          method: 'get',
          url: '/prod-api/getUserInfo'
        }).then(response => {
          if (response.data.code == 200) {
            this.resetSetItem('userName', response.data.data.userName);
            this.resetSetItem('userId', response.data.data.userId);
            this.resetSetItem('userGuid', response.data.data.guid);
            this.resetSetItem('userType', response.data.data.userType);
          }
        });
      },
      getFuncs: async function() {
        let that = this;
        await this.axios({
          method: 'get',
          url: '/prod-api/wechat/getFuncs',
        }).then(response => {
          if (response.data.code == 200) {
            that.funcs = response.data.data;
          } else {
            this.toastText('获取用户权限失败');
          }
        });
      }
    }
  };
</script>
